﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Multirowperipherymillingcutterindexableinsertsarbortype
    {
        public static void _Multirowperipherymillingcutterindexableinsertsarbortype(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 2; //放大系数


            double oal = 20.67;
            double lf = 18.13;
            double dc = 20.6;
            double bd = 19.3;
            double dccb = 13.73;
            double dconms = 7.44;
            double dhub = 13.81;
            double l = 2.86;
            double n = lf - l * 4;
            double lccb = 3.49;


            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal + 4, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 2, v1.Y);
            Vector2 v4 = new Vector2(v3.X, v3.Y + dhub / 2);
            Vector2 v5 = new Vector2(v4.X + oal / 15.425, v4.Y);
            Vector2 v6 = new Vector2(v5.X, v3.Y + bd / 2);
            Vector2 v7 = new Vector2(v6.X + n / 6.138, v6.Y);
            Vector2 v8 = new Vector2(v7.X, v7.Y - l + (dc - bd) / 2);
            Vector2 v9 = new Vector2(v8.X + l, v8.Y);
            Vector2 v10 = new Vector2(v9.X, v9.Y + l);
            Vector2 v11 = new Vector2(v7.X + (dc - bd) / 2, v10.Y);
            Vector2 v12 = new Vector2(v8.X + l / 4.469, v8.Y + l / 4.469);
            Vector2 v13 = new Vector2(v9.X - l / 4.469, v12.Y);
            Vector2 v14 = new Vector2(v13.X, v10.Y - l / 4.469);
            Vector2 v15 = new Vector2(v12.X, v14.Y);
            Vector2 v16 = new Vector2(v8.X + l / 2, v8.Y + l / 2);
            Vector2 v17 = new Vector2(v10.X, v7.Y);
            Vector2 v18 = new Vector2(v17.X + n / 4.181, v17.Y);
            Vector2 v19 = new Vector2(v18.X, v10.Y);
            Vector2 v20 = new Vector2(v19.X + l, v19.Y);
            Vector2 v21 = new Vector2(v20.X, v9.Y);
            Vector2 v22 = new Vector2(v19.X, v21.Y);
            Vector2 v23 = new Vector2(v22.X + l / 4.469, v12.Y);
            Vector2 v24 = new Vector2(v21.X - l / 4.469, v23.Y);
            Vector2 v25 = new Vector2(v24.X, v14.Y);
            Vector2 v26 = new Vector2(v23.X, v25.Y);
            Vector2 v27 = new Vector2(v22.X + l / 2, v22.Y + l / 2);
            Vector2 v28 = new Vector2(v20.X, v18.Y);
            Vector2 v29 = new Vector2(v28.X + n / 3.845, v28.Y);
            Vector2 v30 = new Vector2(v29.X, v20.Y);
            Vector2 v31 = new Vector2(v30.X + l, v30.Y);
            Vector2 v32 = new Vector2(v31.X, v21.Y);
            Vector2 v33 = new Vector2(v30.X, v32.Y);
            Vector2 v34 = new Vector2(v33.X + l / 4.469, v24.Y);
            Vector2 v37 = new Vector2(v32.X - l / 4.469, v34.Y);
            Vector2 v36 = new Vector2(v37.X, v25.Y);
            Vector2 v35 = new Vector2(v34.X, v36.Y);
            Vector2 v38 = new Vector2(v33.X + l / 2, v33.Y + l / 2);
            Vector2 v39 = new Vector2(v31.X, v29.Y);
            Vector2 v42 = new Vector2(v4.X + lf, v31.Y);
            Vector2 v41 = new Vector2(v42.X - l + (dc - bd) / 2, v42.Y);
            Vector2 v45 = new Vector2(v41.X, v32.Y);
            Vector2 v44 = new Vector2(v45.X + l, v45.Y);
            Vector2 v43 = new Vector2(v44.X, v39.Y);
            Vector2 v40 = new Vector2(v41.X, v39.Y);
            Vector2 v46 = new Vector2(v45.X + l / 4.469, v34.Y);
            Vector2 v47 = new Vector2(v44.X - l / 4.469, v46.Y);
            Vector2 v49 = new Vector2(v47.X, v36.Y);
            Vector2 v48 = new Vector2(v46.X, v49.Y);
            Vector2 v50 = new Vector2(v45.X + l / 2, v45.Y + l / 2);
            Vector2 v51 = new Vector2(v4.X + oal, v43.Y);
            Vector2 v52 = new Vector2(v51.X, v51.Y - bd);
            Vector2 v53 = new Vector2(v6.X, v52.Y);
            Vector2 v54 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v55 = new Vector2(v4.X, v54.Y);
            Vector2 v56 = new Vector2(v53.X + lf / 5.63, v53.Y);
            Vector2 v57 = new Vector2(v56.X, v56.Y - (dc - bd) / 2);
            Vector2 v58 = new Vector2(v57.X + l, v57.Y);
            Vector2 v59 = new Vector2(v58.X, v56.Y);
            Vector2 v60 = new Vector2(v56.X + lf / 4.074, v56.Y);
            Vector2 v61 = new Vector2(v60.X, v58.Y);
            Vector2 v62 = new Vector2(v61.X + l, v61.Y);
            Vector2 v63 = new Vector2(v62.X, v60.Y);
            Vector2 v64 = new Vector2(v60.X + lf / 3.882, v60.Y);
            Vector2 v65 = new Vector2(v64.X, v62.Y);
            Vector2 v66 = new Vector2(v65.X + l, v65.Y);
            Vector2 v67 = new Vector2(v66.X, v64.Y);
            Vector2 v68 = new Vector2(v51.X, v3.Y + dccb / 2);
            Vector2 v69 = new Vector2(v68.X - lccb, v68.Y);
            Vector2 v70 = new Vector2(v69.X, v69.Y * -1);
            Vector2 v71 = new Vector2(v68.X, v70.Y);
            Vector2 v72 = new Vector2(v69.X, v3.Y + dconms / 2);
            Vector2 v73 = new Vector2(v4.X, v72.Y);
            Vector2 v74 = new Vector2(v72.X, v72.Y * -1);
            Vector2 v75 = new Vector2(v73.X, v73.Y * -1);
            


            //作图
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            line2.Vertexes.Add(new LwPolylineVertex(v55));
            line2.Vertexes.Add(new LwPolylineVertex(v54));
            fun.PolyFill(dxf, line2, 0.1, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v7));
            line3.Vertexes.Add(new LwPolylineVertex(v6));
            line3.Vertexes.Add(new LwPolylineVertex(v53));
            line3.Vertexes.Add(new LwPolylineVertex(v52));
            line3.Vertexes.Add(new LwPolylineVertex(v51));
            line3.Vertexes.Add(new LwPolylineVertex(v43));
            fun.PolyFill(dxf, line3, 0.1, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v11));
            line4.Vertexes.Add(new LwPolylineVertex(v7));
            line4.Vertexes.Add(new LwPolylineVertex(v8));
            line4.Vertexes.Add(new LwPolylineVertex(v9));
            line4.Vertexes.Add(new LwPolylineVertex(v10));
            line4.Vertexes.Add(new LwPolylineVertex(v11));
            line4.Vertexes[0].Bulge = Math.Tan(82 * pi / 180 / 4);
            fun.PolyFill(dxf, line4, 0.1, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v12));
            line5.Vertexes.Add(new LwPolylineVertex(v13));
            line5.Vertexes.Add(new LwPolylineVertex(v14));
            line5.Vertexes.Add(new LwPolylineVertex(v15));
            line5.Vertexes.Add(new LwPolylineVertex(v12));
            fun.PolyFill(dxf, line5, 0.1, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v17));
            line6.Vertexes.Add(new LwPolylineVertex(v18));
            line6.Vertexes.Add(new LwPolylineVertex(v19));
            line6.Vertexes.Add(new LwPolylineVertex(v20));
            line6.Vertexes.Add(new LwPolylineVertex(v21));
            line6.Vertexes.Add(new LwPolylineVertex(v22));
            line6.Vertexes.Add(new LwPolylineVertex(v18));
            fun.PolyFill(dxf, line6, 0.1, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(v23));
            line7.Vertexes.Add(new LwPolylineVertex(v24));
            line7.Vertexes.Add(new LwPolylineVertex(v25));
            line7.Vertexes.Add(new LwPolylineVertex(v26));
            line7.Vertexes.Add(new LwPolylineVertex(v23));
            fun.PolyFill(dxf, line7, 0.1, contour);

            LwPolyline line8 = new LwPolyline();
            line8.Vertexes.Add(new LwPolylineVertex(v28));
            line8.Vertexes.Add(new LwPolylineVertex(v29));
            line8.Vertexes.Add(new LwPolylineVertex(v30));
            line8.Vertexes.Add(new LwPolylineVertex(v31));
            line8.Vertexes.Add(new LwPolylineVertex(v32));
            line8.Vertexes.Add(new LwPolylineVertex(v33));
            line8.Vertexes.Add(new LwPolylineVertex(v29));
            fun.PolyFill(dxf, line8, 0.1, contour);

            LwPolyline line9 = new LwPolyline();
            line9.Vertexes.Add(new LwPolylineVertex(v35));
            line9.Vertexes.Add(new LwPolylineVertex(v36));
            line9.Vertexes.Add(new LwPolylineVertex(v37));
            line9.Vertexes.Add(new LwPolylineVertex(v34));
            line9.Vertexes.Add(new LwPolylineVertex(v35));
            fun.PolyFill(dxf, line9, 0.1, contour);

            LwPolyline line10 = new LwPolyline();
            line10.Vertexes.Add(new LwPolylineVertex(v39));
            line10.Vertexes.Add(new LwPolylineVertex(v40));
            line10.Vertexes.Add(new LwPolylineVertex(v41));
            line10.Vertexes.Add(new LwPolylineVertex(v42));
            line10.Vertexes.Add(new LwPolylineVertex(v43));
            line10.Vertexes.Add(new LwPolylineVertex(v44));
            line10.Vertexes.Add(new LwPolylineVertex(v45));
            line10.Vertexes.Add(new LwPolylineVertex(v40));
            line10.Vertexes[3].Bulge = Math.Tan(-82 * pi / 180 / 4);
            fun.PolyFill(dxf, line10, 0.1, contour);

            LwPolyline line11 = new LwPolyline();
            line11.Vertexes.Add(new LwPolylineVertex(v48));
            line11.Vertexes.Add(new LwPolylineVertex(v49));
            line11.Vertexes.Add(new LwPolylineVertex(v47));
            line11.Vertexes.Add(new LwPolylineVertex(v46));
            line11.Vertexes.Add(new LwPolylineVertex(v48));
            fun.PolyFill(dxf, line11, 0.1, contour);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v56));
            line12.Vertexes.Add(new LwPolylineVertex(v57));
            line12.Vertexes.Add(new LwPolylineVertex(v58));
            line12.Vertexes.Add(new LwPolylineVertex(v59));
            line12.Vertexes.Add(new LwPolylineVertex(v60));
            line12.Vertexes.Add(new LwPolylineVertex(v61));
            line12.Vertexes.Add(new LwPolylineVertex(v62));
            line12.Vertexes.Add(new LwPolylineVertex(v63));
            line12.Vertexes.Add(new LwPolylineVertex(v64));
            line12.Vertexes.Add(new LwPolylineVertex(v65));
            line12.Vertexes.Add(new LwPolylineVertex(v66));
            line12.Vertexes.Add(new LwPolylineVertex(v67));
            fun.PolyFill(dxf, line12, 0.1, contour);

            Line line13 = new Line(v68, v69);
            line13.Layer = refin;
            line13.Linetype = Linetype.Dashed;
            line13.LinetypeScale = 5;
            dxf.AddEntity(line13);

            Line line14 = new Line(v69, v70);
            line14.Layer = refin;
            line14.Linetype = Linetype.Dashed;
            line14.LinetypeScale = 5;
            dxf.AddEntity(line14);

            Line line15 = new Line(v70, v71);
            line15.Layer = refin;
            line15.Linetype = Linetype.Dashed;
            line15.LinetypeScale = 5;
            dxf.AddEntity(line15);

            Line line16 = new Line(v72, v73);
            line16.Layer = refin;
            line16.Linetype = Linetype.Dashed;
            line16.LinetypeScale = 5;
            dxf.AddEntity(line16);

            Line line17 = new Line(v74, v75);
            line17.Layer = refin;
            line17.Linetype = Linetype.Dashed;
            line17.LinetypeScale = 5;
            dxf.AddEntity(line17);


            fun.drawcircle(dxf, v16, l / 8.29, 0.1, contour);

            fun.drawcircle(dxf, v27, l / 8.29, 0.1, contour);

            fun.drawcircle(dxf, v38, l / 8.29, 0.1, contour);

            fun.drawcircle(dxf, v50, l / 8.29, 0.1, contour);

            //坐标系
            fun.Axis(dxf, v3, -90, 180, "", "", "", 0.3, 1, 0);



            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;


            fun.dimrot1(dxf, v4, v51, 0, oal, 1, height, arrowsize, exline, "OAL,LPR", "", "");

            fun.dimrot1(dxf, v4, v42, 0, oal * 3 / 4, 1, height, arrowsize, exline, "LF,LTA", "", "");

            fun.dimrot1(dxf, v11, v42, 0, oal / 2, 1, height, arrowsize, exline, "APMX", "", "");

            fun.dimrot1(dxf, v70, v71, 180, dconms, 1, height, arrowsize, exline, "LCCB", "", "");

            fun.dimrot1(dxf, v73, v75, 90, dconms, 1, height, arrowsize, exline, "DCONMS", "", "");

            fun.dimrot1(dxf, v4, v55, 90, dhub, 1, height, arrowsize, exline, "DHUB", "", "");

            fun.dimrot1(dxf, v68, v71, -90, dconms, 1, height, arrowsize, exline, "DCCB", "", "");

            fun.dimrot1(dxf, v51, v52, -90, dconms * 2, 1, height, arrowsize, exline, "BD", "", "");

            fun.dimrot1(dxf, v42, v66, -90, dconms * 4, 1, height, arrowsize, exline, "DC", "", "");

            fun.jdbz2(dxf, new Line(v42, fun.Polar(v42, 90 * pi / 180, 0.1)), new Line(v42, fun.Polar(v42, 180 * pi / 180, 0.1)), oal / 2.5, height, arrowsize, exline, "KAPR", "", "");






            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}